package com.csst.action;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Controller;

import com.csst.bean.Order;
import com.csst.util.SignatureTool;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

@Controller
public class BankPayAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8259178463604858009L;
	
	
	
	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		ActionContext context=ActionContext.getContext();
		Map<String,Object> session=context.getSession();
		Map<String,String> map=new HashMap<String,String>();
		Order order=(Order)session.get("order");
		Date date=new Date();
		SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddHHmmss");
		String orderDate=sdf.format(date);
		System.out.println(orderDate);
		context.put("orderDate", orderDate);
		SignatureTool tool = new SignatureTool();
		long m=(long)(order.getMoney()*100);
		String money=String.valueOf(m);
		tool.setPayParameter(order.getIdentNum(), m, 123456, "NM", SignatureTool.NOTIFY_TYPE_HS, orderDate, "jksas-jklwj-lwjjh-wmkhs-jklkj");
		tool.setMerURL("http://192.168.1.67:8080/SSH/bankresult");
		String merSignMsg=tool.signature();
		map.put("orderID", order.getIdentNum());
		map.put("amount", money);
		map.put("merID", "123456");
		map.put("payType", "NM");
		map.put("notifyType", SignatureTool.NOTIFY_TYPE_HS);
		map.put("merURL", "http://192.168.1.67:8080/SSH/bankresult");
		map.put("orderDate", orderDate);
		map.put("merSignMsg", merSignMsg);
//		JSONObject job=new JSONObject(result);
//		System.out.println(job.get("result"));
		context.put("map", map);
		return "success";
	}
	
}
